TGML Script Element: <Script>

Script defines a script block that belongs to the immediate parent element.

Specifying an event attribute on the Script element makes the parent element the target for the specified event. For example, if OnMouseClick and the function name "click" are specified, the click function is executed when the user clicks the parent element (assuming that the element is a visible graphical element).

If the parent element of Script is a container element, such as Component, the mouse event is sent when any of the contained graphical elements are hit. The hit element is the target, while the parent element, which handles the event, is the current target.

The functions are always defined with an in parameter. The parameter is a reference to the event object that can be used to get event specific information and to access the DOM, starting with getTarget or getCurrentTarget.

Each Script element (script block) creates a JavaScript context. Function calls between script blocks (contexts) are not supported, that is, no support for global script functions.

The script functions are stored in the CDATA section of the Script element. The CDATA section is accessible through the Content attribute.

Attribute Type Description

Content

String

The script.
Inheritable: No
Animatable: No

Events and event attributes:

Event Attribute Event Type Target Description

OnDocumentLoad

DocumentLoadEvent

Any element

The TGML document is uploaded (opened).
Cancelable: No

OnMouseClick

MouseClickEvent

Painted element

A mouse button is clicked over an element.
Cancelable: Yes

OnMouseDown

MouseDownEvent

Painted element

A mouse button is pressed over an element.
Cancelable: Yes

OnMouseUp

MouseUpEvent

Painted element

A mouse button is released over an element.
Cancelable: Yes

OnMouseOver

MouseOverEvent

Painted element

The pointer is moved onto an element.
Cancelable: Yes

OnMouseMove

MouseMoveEvent

Bind element

The pointer is moved while it is over an element.
Cancelable: Yes

OnMouseOut

MouseOutEvent

Painted element

The pointer is moved away from an element.
Cancelable: Yes

OnSignalChange

SignalChangeEvent

Painted element

The value of the bound signal has been changed.
The referenced attribute in the Bind element is updated before the event is sent.
Cancelable: Yes

Example:

Copy
<TGML>
    <Rectangle Name="MyRect" Left="50" Top="50" Width="100" Height="100" Fil1="#FFFFFF" Stroke="#000000" >

        <Script OnMouseClick="click"><! [CDATA [ 
            function click (evt)
            {
                var element = evt.getTarget();
                var name = element.getAttribute("Name");

                var mouseX = evt.getClientX(); 
                var mouseY = evt.getClientY();

                var message = "You hit " + name + " at " + mouseX +    "," + mouseY;

                alert(message);
            }
        ] ]></Script>
    </Rectangle>
</TGML>

Example on screen: